package com.codingfly.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/v1")
public class TestController {
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    @Autowired
    private JdbcTemplate jdbcTemplate;
    private static Logger logger = LoggerFactory.getLogger(TestController.class);

    @RequestMapping("/test")
    public List<Map<String, Object>> test() {
         return jdbcTemplate.queryForList("select * from users");
    }

    @RequestMapping("/test-logger-level")
    public Map<String, Object> testLogLevel() {
        System.out.println("\n\n\n\n\n");
        logger.debug("这是debug日志");
        logger.info("这是info日志");
        logger.warn("这是warn日志");
        logger.error("这是error日志");
        System.out.println("\n\n\n\n\n");
        return new HashMap() {{
            put("code", 200);
        }};
    }

}